const fs = require('fs');
const path = require('path');

function  news() {
    const fullPath = path.join(__dirname, './data/news.json');
	const news = fs.readFileSync(fullPath, 'utf-8');
    return JSON.parse(news);
}

function studentsInfo(){
    const fullPath = path.join(__dirname, './data/info.json');
    const students = fs.readFileSync(fullPath, 'utf-8');
    return JSON.parse(students);
}

function luckyStudent(students) {
    const fullPath = path.join(__dirname, './data/info.json');
    let num = parseInt(Math.random() * students.length);
	students[num].count++;
	fs.writeFileSync(fullPath, `${JSON.stringify(students)}`);
    return students[num];
}

module.exports = {
	news,
	studentsInfo,
	luckyStudent,
};
